package com.calligraphy.product.client;


import com.calligraphy.product.common.InventoryDTO;
import com.calligraphy.product.common.ProductInfoOutput;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author hy
 * @Date 2019/1/2 10:18
 **/
@FeignClient(name = "product", fallback = ProductClient.ProductFallback.class)
public interface ProductClient {

    @PostMapping("/provider/listForOrder")
    List<ProductInfoOutput> listForOrder(List<String> productIdList);

    @PostMapping("/provider/decreaseStock")
    void decreaseStock(List<InventoryDTO> InventoryDTOList);

    @PostMapping("/provider/increaseStock")
    void increaseStock(List<InventoryDTO> InventoryDTOList);

    @PostMapping("/provider/findOne")
    ProductInfoOutput findOne(String productId);


    @Component
    static class ProductFallback implements ProductClient{

        @Override
        public List<ProductInfoOutput> listForOrder(List<String> productIdList) {
            System.out.println(
                    "进入熔断"
            );
            return null;
        }

        @Override
        public void decreaseStock(List<InventoryDTO> InventoryDTOList) {}

        @Override
        public void increaseStock(@RequestBody List<InventoryDTO> InventoryDTOList){}

        @Override
        public ProductInfoOutput findOne(String productId) {
            return null;
        }

    }
}

